import pygame, random
from res.conf import window_size
from pygame.locals import Rect
from res.glo import color , default_font


def _get_center(rect):
    return [float((window_size[0] / 2 - rect.centerx)), float((window_size[1] / 2 - rect.centery))]


def _get_center_x(width):
    return float((window_size[0] - width) / 2)


def _get_center_y(height):
    return float((window_size[1] - height) / 2)


def _get_bottom(height):
    return float(window_size[1] - height)


def _create_rect(color, size, border = 0 ):
    surface = pygame.Surface(size).convert_alpha()
    pygame.draw.rect(surface, color, Rect([0, 0], size), border)
    return surface


def _create_image(filename):
    img = pygame.image.load(filename).convert_alpha()
    return img


def _change_size(surface, size):
    return pygame.transform.smoothscale(surface, size)


def _random_pos(width, y):
    randx = random.randint(0, window_size[0])
    randy = random.randint(y, 0)
    return [randx, randy]


def _out_screen(rect):
    return True if rect.x <= 0 or rect.y <= 0 or rect.x >= window_size[0] or rect.y >= window_size[1] else False


def _out_screen_bottom(rect):
    return True if rect.y >= window_size[1] else False


def _create_font( text ,color = color['font']['default'] , font = default_font ):
    return font.render(text, True, color ).convert_alpha()


def _get_right_bottom(rect):
    return window_size[0] - rect.width , window_size[1] - rect.height

